import orgSelect from "@/app_SubCom/orgSelect/index.vue";
import OrgSelectDialog from "@/app_SubCom/orgSelectDialog/orgSelectDialog.vue";
import MsCronInput from "@/components/ms-cron/ms-cron-input.vue";
import basicContainer from "@/components/basic-container/main.vue";

import * as flow from "@/api/flow/flow";
import * as api from "@/api/app_SubCom";
import * as entity from "@/api/modulManage/entity";
import * as workflow from "@/api/plugin/workflow/model";
import * as category from "@/api/plugin/workflow/category";
import * as enumApi from "@/api/modulManage/enum";
import * as c from "@/api/common";

export default {
    data() {
        return {
            pageName: "",
            templateList: [orgSelect, OrgSelectDialog, MsCronInput, basicContainer],
            commonApi: {flow, ...api, ...entity, workflow, category, enumApi, c},
            functionObj: {
                deepCopy: this.deepCopy,
                getOnlyId: this.getOnlyId,
                isJSON: this.isJSON,
                setSearchForm: this.setSearchForm
            },
            loading: true,

            errorObj: null
        };
    },
    methods: {
        dataChange(e) {
            let {detail: {data}} = e;
            if (data["subRouter"]) {
                let {method, url, replaceUrl, reload} = data["subRouter"];
                if (replaceUrl) {
                    this.reload = reload
                    let tag = this.$store.getters.tagList.filter(ele => ele.value === this.$route.fullPath)[0]
                    this.$store.commit('DEL_TAG', tag)
                }
                this.$nextTick(() => {
                    this.$router[method](`/${this.replaceCode}` + url);
                })
            }
        },
        // 子应用渲染结束后触发
        microMounted() {
            this.loading = false;
        },
        //子应用渲染出错时触发
        microError(error) {
            this.errorObj = error.detail.error;
            throw error;
        }
    },
    watch: {
        "$route": {
            handler(v) {
                this.pageName = v.params[0] + localStorage.getItem("appId") + JSON.stringify(v.query);
                this.loading = false
            },
            deep: true,
            immediate: true
        },
    },
}
